import { http } from "@/utils/http";

// 摄像头信息接口类型
export interface Camera {
  id?: number;
  tenantId?: number; // 租户ID
  address: string; // 小区名称
  status: number; // 状态
  deviceName: string; // 设备名称
  installAddress: string; // 安装地址
  maintenancePeriod: string; // 维护周期
  orientation: string; // 方向
  deviceCode: string; // 设备编码
  resolution: string; // 分辨率
  memory: string; // 内存
  ssdCapacity: string; // SSD容量
  installDate: string; // 安装日期
  cpu: string; // CPU
  manufacturer: string; // 制造商
  manufacturerAddress: string; // 制造商地址
  manufacturerPhone: string; // 制造商电话
  responsiblePerson: string; // 负责人
  maintenanceUnit: string; // 维护单位
  maintenanceUnitPhone: string; // 维护单位电话
  maintenanceUnitAddress: string; // 维护单位地址
  equipmentMaintainer: string; // 设备维护人
  registrationDate: string; // 登记日期
  remarks: string; // 备注
}

// 摄像头查询参数接口
export interface CameraQuery {
  page?: number;
  limit?: number;
  tenantId?: number;
  address?: string;
  deviceName?: string;
  deviceCode?: string;
  [key: string]: any;
}

// 摄像头添加参数接口
export interface CameraAdd {
  address: string;
  status: number;
  deviceName: string;
  installAddress: string;
  maintenancePeriod: string;
  orientation: string;
  deviceCode: string;
  resolution: string;
  memory: string;
  ssdCapacity: string;
  installDate: string;
  cpu: string;
  manufacturer: string;
  manufacturerAddress: string;
  manufacturerPhone: string;
  responsiblePerson: string;
  maintenanceUnit: string;
  maintenanceUnitPhone: string;
  maintenanceUnitAddress: string;
  equipmentMaintainer: string;
  registrationDate: string;
  remarks: string;
}

// 摄像头更新参数接口
export interface CameraUpdate {
  id: number;
  address: string;
  status: number;
  deviceName: string;
  installAddress: string;
  maintenancePeriod: string;
  orientation: string;
  deviceCode: string;
  resolution: string;
  memory: string;
  ssdCapacity: string;
  installDate: string;
  cpu: string;
  manufacturer: string;
  manufacturerAddress: string;
  manufacturerPhone: string;
  responsiblePerson: string;
  maintenanceUnit: string;
  maintenanceUnitPhone: string;
  maintenanceUnitAddress: string;
  equipmentMaintainer: string;
  registrationDate: string;
  remarks: string;
}

// 分页响应接口
interface PageResponse<T> {
  total: number;
  list: T[];
}

// 摄像头列表响应
export interface CameraListResponse {
  code: number;
  data: PageResponse<Camera>;
  message: string;
}

// 通用响应接口
export interface ApiResponse<T = any> {
  code: number;
  data?: T;
  message: string;
}

// 获取摄像头列表
export const getCameraList = (params?: CameraQuery) => {
  return http.post<CameraListResponse, CameraQuery>("/camera/list", {
    data: params
  });
};

// 获取摄像头详情
export const getCameraDetail = (id: number) => {
  return http.get<ApiResponse<Camera>, { id: number }>("/camera/info", {
    params: { id }
  });
};

// 添加摄像头
export const addCamera = (data: CameraAdd) => {
  return http.post<ApiResponse, CameraAdd>("/camera/add", {
    data
  });
};

// 更新摄像头
export const updateCamera = (data: CameraUpdate) => {
  return http.request<ApiResponse>("put", "/camera/update", {
    data
  });
};

// 删除摄像头
export const deleteCamera = (id: number) => {
  return http.request<ApiResponse>("delete", "/camera/delete", {
    params: { id }
  });
};

// 批量删除摄像头
export const batchDeleteCamera = (ids: number[]) => {
  return http.request<ApiResponse>("delete", "/camera/deleteByBatch", {
    data: { ids }
  });
};
